package com.Dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import util.DBHelp;
import util.RowMapper;


import com.entity.Goal;




public class GoalDao {
	
	private DBHelp<Goal> db =new DBHelp<Goal>();
	
	
		public List<Goal> findProjectId(int projectid) {
			String sql = "SELECT id,`name`,`desc`,createtime,projectid FROM t_goal WHERE projectid = ?";
			return db.queryForList(sql,new Mr(),projectid);
			}
	
	
	
	class Mr implements RowMapper<Goal>{
		public Goal mapperRow(ResultSet rs) throws SQLException {
			Goal em=new Goal();
			em.setId(rs.getInt("id"));
			em.setName(rs.getString("name"));
			em.setDesc(rs.getString("desc"));
			em.setCreatetime(rs.getString("createtime"));
			em.setProjectid(rs.getInt("projectid"));
			return em;
		}
		
	}



	public void update(Goal p) {
			String sql="UPDATE t_goal SET `name`= ?,`desc`= ? WHERE id = ?";
			db.executeSQL(sql, p.getName(),p.getDesc(),p.getId());
	}

	public void sava(Goal g) {
		String sql = "INSERT INTO t_goal(`name`,`desc`,createtime,employeeid,projectid)VALUES(?,?,?,?,?)";
		db.executeSQL(sql, g.getName(), g.getDesc(), g.getCreatetime(),g.getEmployeeid(),g.getProjectid());
	}

	

	

}
